<template>
  <div>
    <div id="pieDiv" style="width: 600px;height: 300px;"></div>
    <el-row>
      <el-col :span="12"></el-col>
      <el-col :span="10" style="padding-top:10px;padding-right:50px;box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);width: 300px;height: 150px;">
        <el-form
            label-width="120px"
            class="demo-ruleForm"
            status-icon
        >
          <el-form-item label="起始日期">
            <el-input v-model="queryObj.startDate" />
          </el-form-item>

          <el-form-item label="结束日期">
            <el-input v-model="queryObj.endDate" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="initPie()">
              <el-icon style="font-size: 20px;padding-right: 10px;"><Search /></el-icon>查询
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="2"></el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts';
import axios from 'axios';
export default {
  data() {
    return {
      queryObj:{}, //查询条件对象
      pieData:{} // 查询数据对象
    }
  },
  methods:{
    async initPie(){ //初始化饼图
      await axios.get("/project/count/countSell",{
        params:this.queryObj
      }).then(resp =>{
        this.pieData = resp.data;
      })

      var myChart = echarts.init(document.getElementById('pieDiv'));
      let option = {
        title: {
          text: '各类商品销量统计',//主标题
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: '类别',
            type: 'pie',
            radius: '50%',
            data: this.pieData,//饼图数据
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    }
  },
  mounted() {
    this.initPie();
  }
}
</script>

<style scoped>

</style>